package com.jrauto.CarAppBackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jrauto.CarAppBackend.model.Brand;
import com.jrauto.CarAppBackend.service.BrandService;
import com.jrauto.CarAppBackend.mapper.BrandMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author huimin
* @description 针对表【brand(汽车品牌表)】的数据库操作Service实现
* @createDate 2025-06-27 10:32:25
*/
/**
 * 品牌业务逻辑接口实现
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Resource
    private BrandMapper brandMapper;

    @Override
    public boolean addBrand(Brand brand) {
        return save(brand);
    }

    @Override
    public Brand getBrandById(Long id) {
        return getById(id);
    }

    @Override
    public boolean updateBrand(Brand brand) {
        if (brand.getId() == null) {
            throw new IllegalArgumentException("更新品牌时ID不能为空");
        }
        return updateById(brand);
    }

    @Override
    public boolean deleteBrand(Long id) {
        return removeById(id);
    }

    @Override
    public List<Brand> getAllBrands() {
        return list();
    }

    @Override
    public List<Brand> getBrandsByName(String name) {
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Brand::getName, name);
        return list(queryWrapper);
    }
}





